#include <iostream>
#include <cuda_runtime.h>
#include "../common/common.h"
#define DEVICENUM 0

__global__ void vector_dim()
{
    // int index = threadIdx.x;
    int index = threadIdx.x + blockDim.x * blockIdx.x;
    printf("thread_id=%d\n", index);
}

__global__ void matrix_dim()
{
    int ix = threadIdx.x + blockIdx.x * blockDim.x;
    int iy = threadIdx.y + blockIdx.y * blockDim.y;
    int index = ix + iy * blockDim.x * gridDim.x;
    printf("thread_id=%d\n", index);
}

int main(int argc, char **argv)
{
    // dim3 gridSize_v(4);
    // dim3 blockSize_v(8);
    // vector_dim<<<gridSize_v, blockSize_v>>>();

    // dim3 gridSize_m(3, 2);
    // dim3 blockSize_m(5, 3);
    // std::cout << "kernel function grid and block dim:\n"
    //           << "\tgrid.x:" << gridSize_m.x << "\tgrid.y:" << gridSize_m.y << "\n"
    //           << "\tblock.x:" << blockSize_m.x << "\tblock.y:" << blockSize_m.y << "\n"
    //           << "\ttotal thread nums:" << gridSize_m.x * gridSize_m.y * blockSize_m.x * blockSize_m.y << std::endl;
    // matrix_dim<<<gridSize_m, blockSize_m>>>();

    int num_threads = 1024; // 1023,1025
    dim3 block_size = block_dims(num_threads);
    dim3 grid_size = grid_dims(num_threads);
    std::cout << "grid and block dim:\n"
              << "\tgrid.x:" << grid_size.x << "\tgrid.y:" << grid_size.y << "\n"
              << "\tblock.x:" << block_size.x << "\tblock.y:" << block_size.y << std::endl;

    cudaDeviceReset();
    return 0;
}